package com.hpf.cloud.excel;

import cn.hutool.core.io.FileUtil;
import cn.hutool.core.util.StrUtil;
import cn.hutool.poi.excel.ExcelUtil;
import cn.hutool.poi.excel.ExcelWriter;

import java.io.BufferedReader;
import java.util.List;
import java.util.stream.Collectors;

public class FileUtils {

    public static void main(String[] args) {
        BufferedReader bufferedReader = FileUtil.getReader("D:\\Desktop\\xiyu.txt", "UTF-8");
        List<SpainLanguage> spainLanguageList = bufferedReader.lines().map(line -> {
            SpainLanguage spainLanguage = new SpainLanguage();
            List<String> lineContentList = StrUtil.split(line, '|');
            spainLanguage.setWord(lineContentList.get(0));
            spainLanguage.setCertain(lineContentList.get(1));
            spainLanguage.setMeaning(lineContentList.get(2));
            spainLanguage.setSynonym(lineContentList.get(3));
            spainLanguage.setAntonym(lineContentList.get(4));
            spainLanguage.setFeminineOrMasculine(lineContentList.get(5));
            return spainLanguage;
        }).collect(Collectors.toList());
        ExcelWriter writer = ExcelUtil.getWriter("D:\\Desktop\\xiyu_excel.xlsx");
        writer.write(spainLanguageList);
        writer.flush();
    }
}
